package com.asamioffice.goldenport.servlet

import javax.servlet.http.HttpServletRequest
import com.asamioffice.goldenport.text.StringUtil.{liftString => lift}

/**
 * @since   Oct. 12, 2010
 * @version Oct. 15, 2010
 * @version Dec.  3, 2010
 * @author  ASAMI, Tomoharu
 */
object ServletUtil {
  def getContextPath(req: HttpServletRequest) = {
    val path = lift(req.getContextPath)
    if (path.endsWith("/")) path
    else path + "/"
  }

  def getContextServletPath(req: HttpServletRequest) = {
    val path = lift(req.getContextPath) + lift(req.getServletPath)
    if (path.endsWith("/")) path
    else path + "/"
  }

  // try method name form for utility function
  def getPathInfo(req: HttpServletRequest) = {
    lift(req.getPathInfo)
  }

  // try method name form for utility function
  def path_info(req: HttpServletRequest) = getPathInfo(req)
}
